package com.bow.demo.module.zookeeper.curator;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * 
 * ClientFactory
 * 
 * @author vv
 * @since 2016/9/14.
 */
public class ClientFactory {

    /**
     * 根据配置产生一个zk client
     * 
     * @return client
     */
    public static CuratorFramework newClient() {
        String connectionString = "127.0.0.1:2181";
        ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.builder().connectString(connectionString)
                .sessionTimeoutMs(5000).retryPolicy(retryPolicy).build();
        client.start();

        // CuratorFrameworkFactory.newClient(connectionString, retryPolicy)
        // //简单的new
        return client;
    }
}
